package com.example.administrator.yuejian35.Club.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian35.Club.bean.Video;
import com.example.administrator.yuejian35.Club.fragment.viewholder.VideoItemViewHolder1;
import com.example.administrator.yuejian35.Config;
import com.example.administrator.yuejian35.Home.adapter.RecyclerItemViewHolder;
import com.example.administrator.yuejian35.Home.bean.Course;
import com.example.administrator.yuejian35.R;
import com.shuyu.gsyvideoplayer.utils.ListVideoUtil;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import static com.example.administrator.yuejian35.Config.Img_URL;

/**
 * Created by HP on 2017/9/26.
 */

public class VideoListAdapter extends RecyclerView.Adapter {
    private final static String TAG = "RecyclerBaseAdapter";

    private List<Video> itemDataList = null;
    private Context context = null;

    private ListVideoUtil listVideoUtil;


    public VideoListAdapter(Context context, List<Video> itemDataList){
        this.itemDataList = itemDataList;
        this.context = context;

    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //1)  将item.xml 生成 itemView  -  View
        //2)  生成MyViewHolderd对象
        View v = LayoutInflater.from(context).inflate(R.layout.item_video1, parent, false);
        final RecyclerView.ViewHolder holder = new VideoItemViewHolder1(context, v);
        return holder;
    }



    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        //用于绑定数据
        //转换类型m
        VideoItemViewHolder1 videoItemViewHolder= (VideoItemViewHolder1) holder;
        videoItemViewHolder.name.setText(itemDataList.get(position).getVideoname().toString());
        if (!itemDataList.get(position).getVideopic().equals("")){
            Picasso.with(context)
                    .load(Config.CourseImages_URL+itemDataList.get(position).getVideopic())
                    .into(videoItemViewHolder.pic);
        }
        videoItemViewHolder.setListVideoUtil(listVideoUtil);
        videoItemViewHolder.setRecyclerBaseAdapter(this);
        videoItemViewHolder.onBind(position, itemDataList.get(position));





    }

    @Override
    public int getItemCount() {
        return itemDataList.size();
        //return 1;
    }


    @Override
    public int getItemViewType(int position) {
        return 1;
    }


    public void setListData(List<Video> data) {
        itemDataList = data;
        notifyDataSetChanged();
    }

    public ListVideoUtil getListVideoUtil() {
        return listVideoUtil;
    }

    public void setListVideoUtil(ListVideoUtil listVideoUtil) {
        this.listVideoUtil = listVideoUtil;
    }
}
